home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 402_01 / cforms-2.2 / src / cfl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-20  |  2.2 KB  |  107 lines

  1. #include "config.h"
  2. #include "cforms.h"
  3. #include "../patchlevel.h"
  4.  
  5. #ifndef lint
  6. static volatile char *SccsId = "@(#) cfl.c,v 1.4 1993/01/08 16:31:22 lasse Exp";
  7. #endif
  8.  
  9. static char *prog;
  10. /******************************************************************
  11.  *        M A I N
  12.  *        -------
  13.  * Description:
  14.  *    Main routine for the cforms linker, cfl.
  15.  *
  16.  * Arguments:
  17.  *    filenames of forms
  18.  *
  19.  ******************************************************************/
  20. int
  21. main(int argc, char **argv)
  22. {
  23.     FILE *out;
  24.     char module[200];
  25.     char *p;
  26.     int i;
  27.     int comma = 0;
  28.  
  29.     /*
  30.      * Get name of program.
  31.      */
  32.     if ((prog = strrchr(argv[0], SLASH)) != NULL) prog++;
  33.     else prog = argv[0];
  34.  
  35.     /*
  36.      * Check args.
  37.      */
  38.     if (argc < 2) {
  39.     (void)fprintf(stderr, "usage: %s file ...\n", prog);
  40.     exit(1);
  41.     }
  42.  
  43.     /*
  44.      * Print version if required.
  45.      */
  46.     if (strcmp(argv[1], "-v") == 0) {
  47.     (void)printf("CForms linker version %s\n", PATCHLEVEL);
  48.     exit(0);
  49.     }
  50.  
  51.     /*
  52.      * Open the output.
  53.      */
  54.     if ((out = fopen("cforms.c", "w")) == NULL) {
  55.     (void)fprintf(stderr, "%s: failed to open output file: cforms.c", prog);
  56.     exit(1);
  57.     }
  58.  
  59.     /*
  60.      * Print head.
  61.      */
  62.     (void)fprintf(out, "#include <stdio.h>\n");
  63.     (void)fprintf(out, "#include <cforms.h>\n");
  64.  
  65.     /*
  66.      * Print external declarations.
  67.      */
  68.     for(i = 1; i < argc; i++)
  69.     {
  70.             /* Strip path */
  71.         if (p = strrchr(argv[i], SLASH)) p++;
  72.         else p = argv[i];
  73.  
  74.             /* Strip extension */
  75.         strncpy(module, p, sizeof module);
  76.         if (p = strrchr(module, '.')) *p = 0;
  77.  
  78.     (void)fprintf(out, "extern struct module _cf_module_%s;\n", module);
  79.     }
  80.  
  81.     /* 
  82.      * Make the list of modules.
  83.      */
  84.     (void)fprintf(out, "struct module *_cf_modules[] = {\n");
  85.     for(i = 1; i < argc; i++)
  86.     {
  87.     if (comma) {
  88.         (void)fprintf(out, ",\n");
  89.     }
  90.     comma = 1;
  91.  
  92.         /* Strip path */
  93.     if (p = strrchr(argv[i], SLASH)) p++;
  94.     else p = argv[i];
  95.  
  96.         /* Strip extension */
  97.     strncpy(module, p, sizeof module);
  98.     if (p = strrchr(module, '.')) *p = 0;
  99.  
  100.     (void)fprintf(out, "    &_cf_module_%s", module);
  101.     }
  102.     (void)fprintf(out, ",\n    NULL\n};\n");
  103.     fclose(out);
  104.  
  105.     return 0;
  106. }
  107.